<?php
function plugin_render() {
    $result = '';
    $error = '';
    $url = '';
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        $url = trim($_POST['url'] ?? '');
        if (filter_var($url, FILTER_VALIDATE_URL)) {
            $headers = @get_headers($url, 1);
            if ($headers) {
                $result = [
                    'status' => $headers[0] ?? '',
                    'server' => $headers['Server'] ?? '',
                    'ip' => gethostbyname(parse_url($url, PHP_URL_HOST))
                ];
            } else {
                $error = '无法获取HTTP状态，请检查网址。';
            }
        } else {
            $error = '请输入正确的网址（如 https://www.example.com）';
        }
    }
    ?>
    <form method="post" class="space-y-4">
      <div class="flex gap-2">
        <input type="text" name="url" value="<?=htmlspecialchars($url)?>" class="flex-1 border rounded px-3 py-2" placeholder="请输入网址" required>
        <button type="submit" class="bg-blue-500 text-white px-6 py-2 rounded">查询</button>
      </div>
      <?php if ($error): ?>
        <div class="text-red-500"><?=htmlspecialchars($error)?></div>
      <?php endif; ?>
    </form>
    <?php if ($result): ?>
      <div class="mt-4 border rounded p-4 bg-gray-50">
        <div>状态：<span class="font-bold"><?=htmlspecialchars($result['status'])?></span></div>
        <div>服务器：<?=htmlspecialchars($result['server'])?></div>
        <div>IP：<?=htmlspecialchars($result['ip'])?></div>
      </div>
    <?php endif;
} 